package com.xingkeduo.controller.api.marketing;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xingkeduo.controller.base.InitController;
import com.xingkeduo.model.param.MarketingParam.MarketingTypeEnum;
import com.xingkeduo.model.param.MarketingReceiveHistoryParam;
import com.xingkeduo.model.param.MarketingReceiveHistoryParam.MarketingReceiveStatusEnum;
import com.xingkeduo.service.api.marketing.CardService;
import com.xingkeduo.service.api.marketing.StoreService;
import com.xingkeduo.util.Constant;
import com.xingkeduo.util.tool.ResponseMessage;

/**
 * 
 * @ClassName: ManagementCouponController
 * @Description: 市场营销管理-card处理相关
 * @author lixin
 * @date Apr 18, 2019 9:11:07 PM
 *
 */
@RestController
@RequestMapping(Constant.API_URL_PREFIX + "/card")
public class CardController extends InitController {

	@Autowired
	CardService cardService;
	@Autowired
	StoreService storeService;

	/**
	 * 
	 * @Title: getUserCardList
	 * @Description: 获取用户领卡记录
	 * @param @param  marketingReceiveHistoryParam
	 * @param @return 设定文件
	 * @return ResponseMessage 返回类型
	 * @throws @author lixin
	 * @date Apr 30, 2019 10:44:18 AM
	 */
	@PostMapping("/getUserCardList")
	public ResponseMessage getUserCardList(@RequestBody MarketingReceiveHistoryParam marketingReceiveHistoryParam) {
		marketingReceiveHistoryParam.setMarketingType(MarketingTypeEnum.CARD.getCode());
		// 券类型
		if (MarketingTypeEnum.parseStatus(marketingReceiveHistoryParam.getMarketingType())
				.equals(MarketingTypeEnum.UNKNOWN)) {
			return ResponseMessage.error("优惠券，卡类型不合法", 500);
		}
		// 券使用状态
		if (MarketingReceiveStatusEnum.parseStatus(marketingReceiveHistoryParam.getStatus())
				.equals(MarketingReceiveStatusEnum.UNKNOWN)) {
			return ResponseMessage.error("优惠券，卡使用状态不合法", 500);
		}
		// 获取登陆用户id;
		this.initUserInParams(marketingReceiveHistoryParam);
		return cardService.queryCardByTemplate(marketingReceiveHistoryParam);
	}

	
	
	/**
	 * 
	 * @Title: getUserCardDetail
	 * @Description: 查询卡详情
	 * @param @param  marketingReceiveHistoryId
	 * @param @param  request
	 * @param @return 设定文件
	 * @return ResponseMessage 返回类型
	 * @throws @author lixin
	 * @date May 2, 2019 3:04:17 PM
	 */
	@PostMapping("/getUserCardDetail")
	public ResponseMessage getUserCardDetail(@RequestBody MarketingReceiveHistoryParam marketingReceiveHistoryParam) {
		marketingReceiveHistoryParam.setMarketingType(MarketingTypeEnum.CARD.getCode());
		// 领取记录ID
		if (marketingReceiveHistoryParam.getId() == null) {
			return ResponseMessage.error("优惠券，卡记录ID不合法", 500);
		}
		// 券类型
		if (MarketingTypeEnum.parseStatus(marketingReceiveHistoryParam.getMarketingType())
				.equals(MarketingTypeEnum.UNKNOWN)) {
			return ResponseMessage.error("优惠券，卡类型不合法", 500);
		}
		// 获取登陆用户id;
		this.initUserInParams(marketingReceiveHistoryParam);
		return cardService.queryCardDetailByTemplate(marketingReceiveHistoryParam);
	}

	/**
	 * 
	* @Title: getCardStroesList 
	* @Description: 查看卡适用门店 
	* @param @param storeids
	* @param @param request
	* @param @return    设定文件 
	* @return ResponseMessage    返回类型 
	* @throws 
	* @author lixin
	* @date May 2, 2019 3:05:52 PM
	 */
	@PostMapping("/getCardStroesList")
	public ResponseMessage getCardStroesList(Long marketingId,Integer marketingType) {
		return storeService.queryStoresByMarketingId(marketingId,marketingType);
	}

}
